package com.awspaas.user.apps.sts.util;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.util.DBSql;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:Lizj
 * @create: 2022-10-15 23:39
 * @Description: 按钮集成工具类
 */
public class ButttonPostMessageUtil {

    /**
     * 判断该日志中间表中是否存在记录
     * @return
     */
    public boolean hasLog(Map<String,String> paramsMap) {
        String processDefId = paramsMap.get("PROCESSDEFID");
        String processInstId = paramsMap.get("PROCESSINSTID");
        String taskInstId = paramsMap.get("TASKINSTID");
        String bpmButtonId = paramsMap.get("BPMBUTTONID");
        boolean hasLog = false;
        int conuts = DBSql.getInt("select count(*) from BO_PS_MIDDLE_OPERATION_LOG where PROCESS_INSTID = ? AND PROCESS_INSTID = ? AND TASK_INSTID = ? AND  BPMBUTTONID = ?", new Object[]{processDefId, processInstId, taskInstId, bpmButtonId});
        if (conuts!=0) {
            hasLog = true;
        }
        return hasLog;
    }
    /**
     *  判断按钮状态是否为空
     * @return
     *//*
   /* public boolean isStateNull(Map<String,String> paramsMap) {
        String processDefId = paramsMap.get("PROCESS_DEF_ID");
        String processId = paramsMap.get("PROCESSINSTID1");
        String taskInstId = paramsMap.get("TASKINSTID");
        String bpmBtnId = paramsMap.get("BUTTONID");
        boolean isStateNull = false;
        String buttonStatus = DBSql.getString("select BUTTONSTATUS from BO_PS_MIDDLE_OPERATION_LOG where PROCESS_DEF_ID = ? AND PROCESSINSTID1 = ? AND TASKINSTID = ? AND  BUTTONID = ?", new Object[]{processDefId, processId, taskInstId, bpmBtnId});
        if (null!=buttonStatus && !buttonStatus.equals("")) {
            isStateNull = true;
        }
        return isStateNull;
    }
    *//**
     * @methodName: 判断该日志中间表中是否通过（提交需先判断业务日志表其他按钮数据是否通过）
     * @param:
     * @return:
     * @description:
     * @auther: Lizj
     * @date: 2022/10/16 12:40
     *//*
    public boolean IsTransactDealPass(Map<String,String> paramsMap) {
        String bpmBtnId = paramsMap.get("BUTTONID");
        boolean isPass = true;
        if (bpmBtnId.equals("BTN_TRANSACT")) {
            //判断业务日志表其他按钮数据是否通过
            boolean isOtherPass = IsOtherDeal(paramsMap);
            if (isOtherPass) {
                isPass = IsPass(paramsMap);
                return isPass;
            } else {
                return isOtherPass;
            }
        } else {
            isPass = IsPass(paramsMap);
            return isPass;
        }
    }
    *//**
     * 是否通过
     * @return
     *//*
    public boolean IsPass(Map<String,String> paramsMap) {
        String processDefId = paramsMap.get("PROCESS_DEF_ID");
        String processId = paramsMap.get("PROCESSINSTID1");
        String taskInstId = paramsMap.get("TASKINSTID");
        String bpmBtnId = paramsMap.get("BUTTONID");
        boolean isPass = true;
        RowMap rowMap = DBSql.getMap("select * from BO_PS_MIDDLE_OPERATION_LOG where PROCESS_DEF_ID = ? AND PROCESSINSTID1 = ? AND TASKINSTID = ? AND  BUTTONID = ?", new Object[]{processDefId, processId, taskInstId, bpmBtnId});
        if (!"ok".equals(rowMap.getString("BUTTONSTATUS"))) {
            isPass = false;
        }
        return isPass;
    }
    *//**
     * 判断业务日志表其他按钮数据是否通过
     * @return
     *//*
    public boolean IsOtherDeal(Map<String,String> paramsMap){
        String processDefId = paramsMap.get("PROCESS_DEF_ID");
        String processId = paramsMap.get("PROCESSINSTID1");
        String taskInstId = paramsMap.get("TASKINSTID");
        String bpmBtnId = paramsMap.get("BUTTONID");
        boolean isOtherPass = true;
        List<RowMap> rowMaps = DBSql.getMaps("select * from BO_PS_MIDDLE_OPERATION_LOG where PROCESS_DEF_ID = ? AND PROCESSINSTID1 = ? AND TASKINSTID = ? AND  BUTTONID != ?", new Object[]{processDefId, processId, taskInstId, bpmBtnId});
        for (RowMap rowMap : rowMaps) {
            if (!"ok".equals(rowMap.getString("BUTTONSTATUS"))){
                isOtherPass = false;
                break;
            }
        }
        return  isOtherPass;
    }
    *//**
     *  返回未结束办理的业务按钮消息
     * @return
     *//*
    public String getMsg(Map<String,String> paramsMap) {
        String processDefId = paramsMap.get("PROCESS_DEF_ID");
        String processId = paramsMap.get("PROCESSINSTID1");
        String taskInstId = paramsMap.get("TASKINSTID");
        String bpmBtnId = paramsMap.get("BUTTONID");
        String msg = "";
        if (bpmBtnId.equals("BTN_TRANSACT")) {
            boolean isOtherPass = true;
            List<RowMap> rowMaps = DBSql.getMaps("select * from BO_PS_MIDDLE_OPERATION_LOG where PROCESS_DEF_ID = ? AND PROCESSINSTID1 = ? AND TASKINSTID = ? AND  BUTTONID != ?", new Object[]{processDefId, processId, taskInstId, bpmBtnId});
            for (RowMap rowMap : rowMaps) {
                if (!"ok".equals(rowMap.getString("BUTTONSTATUS"))) {
                    isOtherPass = false;
                }
                if (isOtherPass == false) {
                    msg = msg + rowMap.getString("BUTTONNAME");
                }
            }
            if (isOtherPass == false) {
                msg = msg + "等按钮办理未通过，请通过后再进行提交";
            } else {
                if (!IsPass(paramsMap)) {
                    msg = "当前按钮办理未通过";
                }
            }
        } else {
            if (!IsPass(paramsMap)) {
                msg = "当前按钮办理未通过";
            }
        }
        return msg;
    }*/
}
